package com.zslh.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ExitServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session=request.getSession();
		session.invalidate();
		
		Cookie[] cookies=request.getCookies();
		Cookie c1=null;
		Cookie c2=null;
		if(cookies!=null){
			for(Cookie c:cookies){
				if("cookiename".equals(c.getName())){
					c1=c;
					continue;
				}
				if("cookiepwd".equals(c.getValue())){
					c2=c;
					continue;
				}
			}
		}
		
		if(c1!=null&&c2!=null){
			c1.setMaxAge(0);
			c2.setMaxAge(0);
			c1.setPath("/");
			c2.setPath("/");
			
			response.addCookie(c1);
			response.addCookie(c2);
		}
		
		response.sendRedirect("index.jsp");
	}

}
